﻿//-----------------------------------------------------------------------------------
// WebTestRequest Plugin Template version 1.0
//-----------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.WebTesting;

namespace WebServicesTesting.Automation.WebTest.PlugIns
{
    [System.ComponentModel.DisplayName("CacheOutcomePlugin")]
    [System.ComponentModel.Description("TODO: Add a more detailed description of ExceptionPlugin extraction rule.")]
    public class CacheOutcomePlugin : WebTestRequestPlugin
    {
        #region Constructors
        /// <summary>
        /// Default Constructor, remove if not needed
        /// </summary>
        public CacheOutcomePlugin()
        {
        }

        #endregion // Constructors

        #region Properties
        /*
 * Public properties on the class will be surfaced to the user in the VS UI.
 * Only string, int, and bool types are allowed.
 */
        /*
                /// <summary>
                /// Sample string property
                /// </summary>
                private string m_myStringProperty;
                [System.ComponentModel.DisplayName("My String Property")]
                [System.ComponentModel.Description("Enter a long description for this property.")]
                [System.ComponentModel.DefaultValue("MyString")]
                public string MyStringProperty
                {
                    get { return m_myStringProperty; }
                    set { m_myStringProperty = value; }
                }
        */
        #endregion //Properties
        string contextParam1;

        public string ContextParam1
        {
            get { return contextParam1; }
            set { contextParam1 = value; }
        }
        string contextParam2;

        public string ContextParam2
        {
            get { return contextParam2; }
            set { contextParam2 = value; }
        }
        string contextParam3;

        public string ContextParam3
        {
            get { return contextParam3; }
            set { contextParam3 = value; }
        }

        

        #region Overrides
        /*
 * To see a list of overridable methods type "public override " at the class scope.
 */

        /// <summary>
        /// Fires before each request
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void PreRequest(object sender, PreRequestEventArgs e)
        {
            // Access the request via e.Request property to modify the request before it is fired.

            // You can optionally control the execution of this request via 
            // the e.instruction property
            //
            //  e.Instruction = WebTestExecutionInstruction.Execute;
            //  e.Instruction = WebTestExecutionInstruction.Skip;
        }

        /// <summary>
        /// Fires after each request
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void PostRequest(object sender, PostRequestEventArgs e)
        {
            
            try
            {
                if (e.WebTest.Context[ContextParam1].Equals(e.WebTest.Context[ContextParam2]))
                {
                    if (e.WebTest.Context[ContextParam1].Equals(e.WebTest.Context[ContextParam3]))
                    {
                        e.Request.Outcome = Outcome.Fail;

                    }
                    else
                    {
                        e.Request.Outcome = Outcome.Pass;
                    }
                }
                else
                {
                    e.Request.Outcome = Outcome.Fail;

                }
            }
            catch (Exception exe)
            {
                string str = String.Format(CultureInfo.CurrentCulture, "{ValidationRule1} Exception: {0}", exe.Message.ToString());
                
            }
               
        }


        #endregion // Overrides
    }
}